<?php
require('lib/verify.php');
require('lib/has_char.php');
require('lib/is_approved.php');

$_category = "wardkp";
$_title = "Character";
require('lib/head.php');

$id = $_GET["id"];
$system_id = $system["system_id"];

$sql = "select * from wm_characters where character_id = $id and character_system_id = $system_id";
$result = $db->query($sql);


if($db->num_rows($result)<1) {
    header("Location: <?php echo $war_http ?>/error-wrong-system.php");
    exit;
 }


$chara = $db->fetch_assoc($result);

$id = $_GET["id"];

$sql = "select * from subc_users where id = '" . $chara["character_forum_id"] . "'";
$result = $db->query($sql);
$fora = $db->fetch_assoc($result);

boxTop("wardkp: $_title / " . $chara["character_name"]);
?>
<?cclass($chara["character_class"])?> <b><?=$chara["character_name"]?></b>
    <?php
    if($chara["character_forum_id"]) {
        ?>
        <a href="<?php echo $pun_http ?>/profile.php?id=<?=$fora["id"]?>"><?=$fora["username"]?></i></a> (<a href="<?php echo $pun_http ?>/message_send.php?id=<?=$fora["id"]?>">send PM</a>)
        <?php
    }
    else {
        ?>
        <i>Not registered on the forums.</i>
            <?php
            }
?>
<br /><br />
<a href="wishlist-other.php?id=<?=$id?>"><?=$chara["character_name"]?>'s Wishlist</a><br />
<?php //'
    ?>
    <br />

    <b>Earned DKP</b>: <?=number_format($chara["character_dkp_earned"], 2)?><br />
    <b>Spent DKP</b>: <?=number_format($chara["character_dkp_spent"], 2)?><br />
    <b>Current DKP</b>: <b><?=number_format($chara["character_dkp"], 2)?></b><br />

    <br />
    <b>Loot</b><br />
    <?php

    // Speed-up: new/old 0.05/0.20
    /*$sql = "select *, wm_characters.*, wm_credits.*, wm_instances.*, wm_raids.*, wm_bosses.*, wm_item_values.*
     from wm_loots, wm_characters, wm_credits, wm_bosses, wm_raids, wm_instances, wm_item_values
     where loot_system_id = $system_id and
     loot_character = $id and
     wm_item_values.item_system_id = $system_id and
     wm_characters.character_id = loot_character and
     wm_credits.credit_id = wm_loots.loot_credit and
     wm_bosses.boss_id = wm_credits.credit_boss and
     wm_raids.raid_id = wm_credits.credit_raid and
     wm_instances.instance_id = wm_bosses.boss_instance and
     wm_item_values.item_id = wm_loots.loot_item
     order by wm_credits.credit_date desc";
    */

    $sql = "select *, wm_characters.*, wm_credits.*, wm_instances.*, wm_raids.*, wm_bosses.*, wm_item_values.*
            from wm_loots, wm_characters, wm_credits, wm_bosses, wm_raids, wm_instances, wm_item_values
            where loot_system_id = $system_id and
                  loot_character = $id and
                  wm_item_values.item_system_id = $system_id and
                  wm_characters.character_id = loot_character and
                  wm_loots.loot_item and
                  wm_credits.credit_id = wm_loots.loot_credit and
                  wm_bosses.boss_id = wm_credits.credit_boss and
                  wm_raids.raid_id = wm_credits.credit_raid and
                  wm_instances.instance_id = wm_bosses.boss_instance and
                  wm_item_values.item_id = wm_loots.loot_item
            order by wm_credits.credit_date desc";

$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> items looted.</i><br />
    <?php
    //
    //Loot links
    //y
    while($loot = $db->fetch_assoc($result)) {
        echo '<br />';
        show_link(array("item_id" =>$loot["loot_item"]));
        if ($loot["loot_level"] == 1) {
            echo bid2text($loot["loot_level"]).'<br />';
        } else {
            echo bid2text($loot["loot_level"]).' ('.number_format($loot["loot_bid"], 2).' bid) ('.number_format($loot["item_value"], 2).' paid)<br />';
        }
        echo '<a href="raids.php?a=view&id='.$loot["raid_id"].'">'.$loot["boss_name"].', '.date("g:i a", strtotime($loot["credit_date"])).'</a><br />';
	echo '<a href="raids.php?a=view&id='.$loot["raid_id"].'">'.$loot["instance_name"].', '.date("D d M Y", strtotime($loot["raid_date"])).'</a><br/>';

    }
echo '<br /><b>Credits</b><br />';

$sql = "select *, wm_raids.*, wm_credits.*, wm_bosses.*, wm_instances.* from wm_attendees left join wm_credits on wm_attendees.attendee_credit = wm_credits.credit_id left join wm_bosses on wm_bosses.boss_id = credit_boss left join wm_raids on wm_credits.credit_raid = wm_raids.raid_id left join wm_instances on wm_instances.instance_id = wm_bosses.boss_instance where attendee_system_id = $system_id and attendee_character=$id and attendee_satout=0 order by credit_date desc";
$result = $db->query($sql);
?>
<i><?=$db->num_rows($result)?> credits earned.</i><br />
    <?php
    //while($cred = $db->fetch_assoc($result)) {
    //	echo '<a href="raids.php?id='.$loot["raid_id"].'">'.$cred["boss_name"].', '.date("g:i a", strtotime($cred["credit_date"])).'</a> in <a href="raids.php?id='.$cred["credit_raid"].'">'.$cred["instance_name"] . ", " . date("D d M Y", strtotime($cred["raid_date"])).'</a><br />';

    //}
    while($cred = $db->fetch_assoc($result)) {
	if(is_numeric($cred["raid_id"])) {
            echo '<a href="raids.php?a=view&id='.$cred["raid_id"].'">'.$cred["boss_name"].', '.date("g:i a", strtotime($cred["credit_date"])).'</a> in <a href="raids.php?a=view&id='.$cred["raid_id"].'">'.$cred["instance_name"] . ", " . date("D d M Y", strtotime($cred["raid_date"])).'</a><br />';
	}
    }


boxBot();

require('lib/foot.php');
?>

